<?php
class Solution {

    /**
     * @param Integer[] $nums
     * @return Integer
     */
    function findMin($nums) {
        $left = 0 ;
        $right = count($nums)-1;
        if ($left == $right)
            return $nums[$left];
        if ($nums[$right] > $nums[0])
            return $nums[0];
        while ($left < $right){
            $mid = (($right - $left) >> 1) + $left;
            if ($nums[$mid] > $nums[$mid + 1])
                return $nums[$mid + 1];
            if ($nums[$mid - 1] > $nums[$mid])
                return $nums[$mid];
            if ($nums[$left] < $nums[$mid]){
                $left = $mid ;
            } else {
                $right = $mid ;
            }
        }
        return $nums[$right];
    }
}
